package com.apps.ftapp.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.apps.ftapp.R;
import com.apps.ftapp.activity.DefPlaybackActivity;
import com.apps.ftapp.util.Constant;
import com.apps.ftapp.util.Tools;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/10/24.
 */

public class MyAdapterLesson extends RecyclerView.Adapter {

    protected List<Map<String, Object>> mData;
    private Context context;

    public void setData(List<Map<String, Object>> data, Context context) {
        mData = data;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHolder viewHolder = (ViewHolder) holder;

        viewHolder.mTextView.setText(Tools.isNull(mData.get(position).get("title")));
        viewHolder.shixueTime.setText(Tools.isNull(mData.get(position).get("times")));

        viewHolder.diai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //通知公告

//live.直播课 normal.录播课
                if ("live".equals(Tools.isNull(mData.get(position).get("type")))) {


//
//                    Intent intent1 = new Intent(context, DuoBActivity.class);
//                    intent1.putExtra("roomId",Tools.isNull(mData.get(position).get("roomId")));
//                    intent1.putExtra("title",Tools.isNull(mData.get(position).get("title")));
//                    intent1.putExtra("type",Tools.isNull(mData.get(position).get("type")));
//                    intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
//                    context.startActivity(intent1);


//                    Intent intent = new Intent(getApplicationContext(), com.apps.wsapp.activity.DefPlaybackActivity.class);
//                    intent.putExtra("appKey", Constant.APPKEY);
//                    intent.putExtra("nickname", "我爱为师");
//                    intent.putExtra("partner", Constant.PID);
//                    intent.putExtra("roomId", dataBean.getRoomId());
//                    intent.putExtra("uid", Constant.uid);
//                    intent.putExtra("title",dataBean.getTitle());
//                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
//                    getApplicationContext().startActivity(intent);


                    Intent intent = new Intent(context, DefPlaybackActivity.class);
                    intent.putExtra("appKey", Constant.APPKEY);
                    intent.putExtra("nickname", "我爱为师");
                    intent.putExtra("partner", Constant.PID);
                    intent.putExtra("roomId", Tools.isNull(mData.get(position).get("roomId")));
                    intent.putExtra("uid", Constant.uid);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                    context.startActivity(intent);

                } else {
                    Intent intent = new Intent(context, DefPlaybackActivity.class);
                    intent.putExtra("appKey", Constant.APPKEY);
                    intent.putExtra("nickname", "我爱为师");
                    intent.putExtra("partner", Constant.PID);
                    intent.putExtra("roomId", Tools.isNull(mData.get(position).get("roomId")));
                    intent.putExtra("uid", Constant.uid);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                    context.startActivity(intent);
                }


            }
        });
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView mTextView;
        public TextView shixueTime;
        RelativeLayout diai;

        public ViewHolder(View itemView) {
            super(itemView);
            diai = itemView.findViewById(R.id.diai);
            mTextView = itemView.findViewById(R.id.shixue_title);
            shixueTime = itemView.findViewById(R.id.shixue_time);
        }
    }

}
